<?php @session_start();?>
<?php 
include_once './util/ArrayList.php';
include_once './util/db/model/Product.php';
include_once './util/db/model/ProdType.php';
include_once './util/db/model/ProdAttr.php';
include_once './util/db/model/ProdSubType.php';
include_once './util/db/model/SupplierBrand.php';
include_once './util/db/model/ProductSearchPara.php';
include_once './util/db/service/ProductDBUtil.php';
include_once './util/db/service/ProdAttrDBUtil.php';
include_once './util/db/service/OrderListDBUtil.php';
include_once './util/db/service/ProdTypeDBUtil.php';
include_once './util/db/service/SupplierBrandDBUtil.php';
$prodAttrDBUtil=new ProdAttrDBUtil();
$product = new Product();
if(isset($_REQUEST["p_id"])){
	$p_id=$_REQUEST["p_id"];
	$productDBUtil = new ProductDBUtil();
	$product = $productDBUtil->queryByPid($p_id);
}
if(isset($_POST["attr"])){
	$pa_id=@$_POST["pa_id"];
	$attr=$_POST["attr"];
	$count=$_POST["count"];
	for($i=0;$i<count($pa_id);$i++){
		$prodAttr=new ProdAttr();
		$prodAttr->setP_id($p_id);
		$prodAttr->setPa_id($pa_id[$i]);
		$prodAttr->setCount($count[$i]);
		$prodAttr->setAttr($attr[$i]);
		$prodAttrDBUtil->updateDate($prodAttr);
	}
	$temp=count($attr)-1;
	if($attr[$temp]){
		$prodAttr=new ProdAttr();
		$prodAttr->setP_id($p_id);
		if(null==$count[$temp] || $count[$temp]==""){
			$prodAttr->setCount(0);
		}else{
			$prodAttr->setCount($count[$temp]);
		}
		$prodAttr->setAttr($attr[$temp]);
		$prodAttrDBUtil->insertNewDate($prodAttr);
	}
}




?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/supplier.dwt" codeOutsideHTMLIsLocked="false" -->

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<!-- InstanceBeginEditable name="doctitle" -->

<title>庫存管理</title>

<!-- InstanceEndEditable -->

<style type="text/css">

<!--

#cantainer {

	width: 955px;

	margin-right: 33px;

	margin-left: 33px;

}

#header {

	width: 955px;

	margin-bottom: 10px;

	background-image: url(../../images/top_bg.png);

	height: 82px;

}

#body {

	width: 955px;

	margin-bottom: 10px;

}

#footer {

	width: 955px;

}

.style2 {color: #666666;

	font-size: 12px;

}

#contant_list {

	float: left;

	width: 180px;

	margin-right: 10px;

}

.style17 {color: #74B9E5; font-size: 14px; }

.style43 {font-size: 12px; color: #666666; font-weight: bold; }

#contant_body {

	float: right;

	width: 765px;

}

-->

</style>

<!-- InstanceBeginEditable name="head" -->

<style type="text/css">

<!--

#contant_body_header {

	background-image: url(../../admin/images/admin_inventory_list_header.png);

	height: 62px;

	width: 765px;

	margin-bottom: 10px;

}

#contant_body_body {

	width: 765px;

	margin-bottom: 10px;

}

.style44 {color: #000000}

.style50 {font-size: 9px;

	color: #FF0000;

}

#contant_body_1 {

	background-image: url(../../admin/images/admin_product_add.png);

	width: 737px;

	margin-right: 10px;

	margin-left: 10px;

	height: 25px;

	margin-bottom: 10px;

}

#contant_body_2 {width: 737px;

	margin-right: 10px;

	margin-bottom: 10px;

	margin-left: 10px;

}

#contant_body_5 {width: 737px;

	margin-right: 10px;

	margin-left: 10px;

	margin-bottom: 10px;

}

-->

</style>

<!-- InstanceEndEditable -->
<?php 
$productDBUtil=new ProductDBUtil();
$product=$productDBUtil->queryByPid($p_id);
?>
<script src="../../admin/js/jquery.js"></script>
<script charset="utf-8" src="../../admin/js/utils.js"></script>
<script charset="utf-8" src="../../admin/js/validate.js"></script>
<script type="text/javascript" src="../../admin/js/global.js"></script>

<link rel="stylesheet" type="text/css" href="../../admin/css/jquery-ui-1.8.13.custom.css"></link>
<link rel="stylesheet" type="text/css" href="../../admin/css/validate.css"></link>
<link href="../../admin/css/jquery.ui.theme.css" rel="stylesheet" type="text/css"/>
<script src="../../admin/js/jquery-ui.min.js"></script>
<script src="../../admin/js/jquery.ui.datepicker-zh-TW.js"></script>

<script text="javascript">
function changeCount(index , add){
	var count=document.getElementsByName("count[]")[index];
	var value=parseInt(count.value);
	if(add){
		count.value=value+1;	
	}else{
		if(value>0){
			count.value=value-1;
		}
	}
}

function checkform(form) {
	return $.validator.validateForm(form);
}


function procQuery()
{
	var f=document.getElementById("form22");
	if( checkform(f)){
		f.submit();
	}
}

function addColumn(){
	var html = '';
	html += '<tr>';
    html += '                                    <td width="8%" align="center" class="style44">新增</td>';
    html += '                                    <td width="39%" align="center">';
    html += '                                        <label>';
    html += '                                        <input type="text" name="attr[]" value="" size="10"/>';
    html += '                                        </label>';
    html += '                                    </td>';
    html += '                                    <td width="33%" align="center">';
    html += '                                        <label>';
    html += '                                        <input name="count[]" type="text" value="" size="10" />';
    html += '                                        </label>';
    html += '                                    </td>';
    html += '                                    <td width="6%">';
    html += '                                        <label>';
    html += '                                        <input type="button" name="button12" id="button12" value="+" onclick="addColumn();"/>';
    html += '                                        </label>';
    html += '                                    </td>';
    html += '                                    <td width="5%">';
    html += '                                        <label>';
    html += '                                        <input type="button" name="button12" id="button13" value="-" onclick="delColumn(this);"/>';
    html += '                                        </label>';
    html += '                                    </td>';
    html += '                                    <td width="9%">&nbsp;</td>';
     html += '                                 </tr>';
	$("#spot").append(html);
}

function delColumn(obj){
	if($("[name='attr[]']").length>1){
		if(!isNaN($(obj).parent().parent().parent().find("[name='pa_id[]']").val())){
			$("#del_pa_id_id").val($("#del_pa_id_id").val()+","+$(obj).parent().parent().parent().find("[name='pa_id[]']").val());
		}
		$(obj).parent().parent().parent().remove();
	}
}
</script>
</head>



<body>

<table width="1024" align="center" cellpadding="0" cellspacing="0">

  <tr>

    <td><div id="cantainer">

      <div id="header"></div>

      <div id="body">
       <div id="contant_list">
        <?php include_once './template/Category.php';?>
        </div>


        <!-- InstanceBeginEditable name="EditRegion1" -->

        <div id="contant_body">

          <div id="contant_body_header"></div>
<form id="form22" name="form22" method="post" action="supplier_inventory_change.php" >
<input type="hidden" name="del_pa_id" id="del_pa_id_id" value="0" />
                    <div id="contant_body_2">
                    
                      <table width="737" cellpadding="5" cellspacing="0">
                        <tr>
                          <td align="left" class="style2 style44">商品貨號</td>
                          <td colspan="3" class="style2"><?php echo $product->getProd_no();?></td>
                        </tr>
                        <tr>
                          <td align="left" bgcolor="#E2F8F6" class="style2 style44">商品原始貨號</td>
                          <td colspan="3" bgcolor="#E2F8F6" class="style2">
                          <input type="hidden" name="p_id" value="<?php echo $product->getP_id();?>"/>
                          <?php echo $product->getP_id();?></td>
                        </tr>
                        <tr>
                          <td width="120" align="left" class="style2 style44">商品名稱</td>
                          <td colspan="3" class="style2"><?php echo $product->getP_name();?></td>
                        </tr>
                        <tr>
                          <td align="left" bgcolor="#E2F8F6" class="style2 style44">商品類別</td>
                          <td width="116" bgcolor="#E2F8F6" class="style2"><?php echo $product->getProdType()->getType();?></td>
                          <td width="118" bgcolor="#E2F8F6" class="style2"><?php echo $product->getProdSubType()->getSub_type();?></td>
                          <td width="341" bgcolor="#E2F8F6" class="style2 style44">&nbsp;</td>
                        </tr>
                        <tr>
                          <td align="left" class="style2 style44">製造商</td>
                          <td colspan="3" class="style2 style44"><?php echo $product->getSupplierBrand()->getLogo_name();?> / <?php echo $product->getSupplierBrand()->getLogo_name_en();?>
                            <label></label></td>
                        </tr>
                        <tr>
                          <td align="left" bgcolor="#E2F8F6" class="style2 style44">訂價</td>
                          <td colspan="3" bgcolor="#E2F8F6" class="style2">NT$<?php echo number_format($product->getPrice(), 0, '.', ',');?></td>
                        </tr>
                        <tr>
                          <td align="left" class="style2 style44">售價</td>
                          <td colspan="3" class="style2">NT$<?php echo number_format($product->getSell_price(), 0, '.', ',');?></td>
                        </tr>
                        <tr>
                          <td align="left" bgcolor="#E2F8F6" class="style2 style44">販售方式</td>
                          <td colspan="3" bgcolor="#E2F8F6" class="style2">
                          <?php 
                          	switch ($product->getSell_mode()){
                          		case 1:
                          			echo "正品";
                          			break;
                          		case 2:
                          			echo "特價";
                          			break;
                          		case 3:
                          			echo "預售";
                          			break;
                          		case 4:
                          			echo "下架";
                          			break;
                         	}
                          ?></td>
                        </tr>
                        <tr>
                          <td align="left" class="style2 style44">商品 尺寸/數量<br />
                              <span class="style50">**如無尺寸請於尺寸欄位填寫單一尺寸</span></td>
                          <td colspan="3" class="style2"><table width="100%" cellspacing="0" cellpadding="5">
                              <tr>
                                <td width="45" bgcolor="#CCCCCC">&nbsp;</td>
                                <td width="212" bgcolor="#CCCCCC"><div align="center">尺寸</div></td>
                                <td width="181" bgcolor="#CCCCCC"><div align="center">數量</div></td>
                                <td width="115" bgcolor="#CCCCCC">&nbsp;</td>
                              </tr>
                              <tr>
                                <td colspan="4">
                                
                                <?php 
                                	
                                	$array= $prodAttrDBUtil->queryByPid($product->getP_id());
                                ?>
                                
                                <table width="100%" cellspacing="0" cellpadding="5">
                                    
                                    <?php 
                                    	for($i=0;$i<$array->size();$i++){
                                    ?>

                                    <tr>
                                      <td width="8%" align="center" class="style44"><?php echo ($i+1);?></td>
                                      <td width="39%" align="center"><input type="text" name="attr[]" value="<?php echo $array->get($i)->getAttr()?>" size="10" class="not-null:true"/></td>
                                      <td width="33%" align="center">
                                      	  <input type="hidden" name="pa_id[]" value="<?php echo $array->get($i)->getPa_id();?>"/>
                                          <label>
                                          <input name="count[]" type="text" value="<?php echo $array->get($i)->getCount();?>" size="10" class="datatype:INT" />
                                          </label>
                                      </td>
                                      
                                      <td width="6%">
                                          <label>
                                          <input type="button" name="button9" id="button9" value="+" onclick="addColumn()"/>
                                          </label>
                                      </td>
                                      <td width="5%">
                                          <label>
                                          <input type="button" name="button10" id="button10" value="-" onclick="delColumn(this);"/>
                                          </label>
                                      </td>
                                      <td width="9%">&nbsp;</td>
                                    </tr>
                                    
                                    <?php }?>
                                  </table>
                                    <table id="spot" width="100%" cellspacing="0" cellpadding="5">
                                      <tr>
                                        <td width="8%" align="center" class="style44">新增</td>
                                        <td width="39%" align="center">
                                            <label>
                                            <input type="text" name="attr[]" value="" size="10"/>
                                            </label>
                                        </td>
                                        <td width="33%" align="center">
                                            <label>
                                            <input name="count[]" type="text" value="" size="10" />
                                            </label>
                                        </td>
                                        <td width="6%">
                                            <label>
                                            <input type="button" name="button12" id="button12" value="+" onclick="addColumn();"/>
                                            </label>
                                        </td>
                                        <td width="5%">
                                            <label>
                                            <input type="button" name="button12" id="button13" value="-" onclick="delColumn(this);"/>
                                            </label>
                                        </td>
                                        <td width="9%">&nbsp;</td>
                                      </tr>
                                  </table>
                                  
                                  </td>
                              </tr>
                          </table></td>
                        </tr>
                      </table>
                      
                    </div>

                  <div id="contant_body_5">

                      <table width="100%" cellspacing="0" cellpadding="0">

                        <tr>

                          <td align="center">

                              <label>

                              <input type="button" name="button7" id="button7" value="修改" onclick="procQuery()"/>
                              </label>

                              <label>

<input type="button" name="button8" id="button8" value="回上一頁" onclick="javascript:history.back()"/>
                              </label>
                                                        </form></td>

                        </tr>

                      </table>

                  </div></td>

                <td width="4" background="../../member/img/member_body_right.jpg">&nbsp;</td>

              </tr>

              <tr>

                <td height="9" colspan="3"><img src="../../member/img/member_body_down.jpg" width="765" height="9" /></td>

              </tr>

            </table>

          </div>

        </div>

        <!-- InstanceEndEditable --></div>

      <div id="footer">

        <?php include_once './template/footer.php';?>
      </div>

      </div></td>

  </tr>

</table>

</body>

<!-- InstanceEnd --></html>
